import java.util.*;

public class Text {
    public static int findTheLongestBalancedSubstring(String s) {
        int max=0;
        for(int i=0;i<s.length();i++) {
            if(s.charAt(i) == '0') {
                int count = 0;
                int index = i;
                while(index < s.length() &&s.charAt(index) == '0')   {
                    count++;
                    index++;
                }
                int j = count;
                int count1 = 0;
                while(index < s.length() && s.charAt(index) == '1' && j != 0) {
                    index++;
                    count1++;
                    j--;
                }
                if(j == 0) {
                    if(max < count*2){
                        max = count*2;
                    }
                    i+=count*2-1;
                }else if(count > count1) {
                    if(max < count1*2) {
                        max = count1*2;
                    }
                    if(count1 != 0) {
                        i += count1 * 2 - 1;
                    }
                }
            }
        }
        return max;
    }
    public static List<Integer> finddiv(int num) {
        List<Integer> list = new ArrayList<>();
        for(int j = 2;j*j <= num;j++) {
            if(num%j == 0) {
                list.add(j);
                if(num/j != j) {
                    list.add(num/j);
                }
            }
        }
        return list;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[] array = new int[m+1];
            for(int i=0;i<array.length;i++) {
                array[i] = -1;
            }
            array[n] = 0;
            for(int i = n;i<=m;i++) {
                if(array[i] == -1) {
                    continue;
                }
                List<Integer> list = finddiv(i);
                for(int num:list) {
                    if(i+num <= m) {
                        if(array[i+num] == -1) {
                            array[i+num] = array[i]+1;
                        }else {
                            array[i+num] = Math.min(array[i+num],array[i]+1);
                        }
                    }
                }
            }
            System.out.println(array[m]);
        }
    }
}
